﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StructureMap.Configuration.DSL;
using StructureMap.Pipeline;
using System.Configuration;
using StructureMap.Building.Interception;
using StructureMap;
using Core.IServices;
using Services;

namespace DI
{
    public class ServiceRegistry : Registry
    {
        public ServiceRegistry(ILifecycle lifecycle)
        {            
            Scan(x =>
            {
                x.Assembly("Insurance.Services");
                x.Include(t => !t.IsAbstract && t.Name.EndsWith("Service"));
                x.WithDefaultConventions().OnAddedPluginTypes(c => c.LifecycleIs(lifecycle));
            });            
            Scan(x =>
            {
                x.Assembly("Share.Enterprise");
                x.Include(t => !t.IsAbstract && t.Name.EndsWith("Service"));
                x.WithDefaultConventions().OnAddedPluginTypes(c => c.LifecycleIs(lifecycle));
            });

            For(typeof(IGenericReaderService<,,,>)).LifecycleIs(lifecycle).Use(typeof(GenericReaderService<,,,>));
            For(typeof(IGenericWriterService<,,,>)).LifecycleIs(lifecycle).Use(typeof(GenericWriterService<,,,>));            
        }              
    }
}
